package org.yamikaze.unit.test.mock;

import java.lang.reflect.Method;

/**
 * @author qinluo
 * @date 2023/2/4 19:29
 * @since 1.0.0
 */
public class InvocationKey {

    private final Method method;
    private final Object target;

    public InvocationKey(Method method, Object target) {
        this.method = method;
        this.target = target;
    }

    @Override
    public int hashCode() {
        return method.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        // Self-validate
        if (obj == this) {
            return true;
        }

        // type check
        if (!(obj instanceof InvocationKey)) {
            return false;
        }

        InvocationKey key = (InvocationKey)obj;
        return key.method == this.method && key.target == this.target;
    }
}
